package com.fhz.day006.`fun`

import android.content.SharedPreferences
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract

/**
 * 时间:2021/10/20
 * @author msfeng
 * 简述: TODO
 */
fun main() {

    //::add方法应用
//    var a  =num1AndNum2(1,2) { n1, n2 ->
//        n1 - n2
//    }
//
//    println(a)

    val apply = StringBuilder().apply {
        append("11")
        append("11")
        append("11")
    }
    println(apply)


    val build = StringBuilder().build {
        append("222")
        append("222")
        append("222")
    }
    println(build)



}


inline fun SharedPreferences.open(block:SharedPreferences.Editor.() -> Unit){
    val editor = edit()
    editor.block()
    editor.apply()
}

//内联函数
inline fun <T> T.apply(block: T.() -> Unit): T {
    block()
    return this
}

//高阶函数
fun  <T> T.build(block:T.()->Unit):T{
    block()
    return this
}





//高阶函数
fun num1AndNum2(num1:Int,num2:Int,abc:(Int,Int)->Int):Int{
    val result = abc(num1,num2)
    return result
}
//
//fun add(n:Int ,n2:Int):Int{
//    return n+n2
//}
//
//fun minus(n:Int ,n2:Int):Int{
//    return n-n2
//}
